package apps.softtech.fastmarket.adapter;



import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;


import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import apps.softtech.Utility.ApplicationConstants;
import apps.softtech.Utility.BitmapManager;
import apps.softtech.fastmarket.R;
import apps.softtech.fastmarket.model.UserInfo;

public class AdapterSearchUser extends BaseAdapter{

	ArrayList<UserInfo> mUserInfoList = new ArrayList<UserInfo>();
	LayoutInflater inf;
	Context mContext;
	
	BitmapManager mBitmapManager;
	
	DisplayImageOptions options;
	ImageLoader imageloader;
	public AdapterSearchUser(ArrayList<UserInfo> mUserInfoList,Context mContext,DisplayImageOptions options){
		this.mUserInfoList  = mUserInfoList;
		this.mContext = mContext;
		inf = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.options = options;
	}
	@Override
	public int getCount() {
		if(mUserInfoList.size()==0){
			return 1;
		}
		return mUserInfoList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View vi, ViewGroup arg2) {
		ViewHolder vh =null;
		if(mUserInfoList.size()==0|| mUserInfoList==null||mUserInfoList.equals(null)){
			vi = inf.inflate(R.layout.search_no_result, null);
			return vi;
		}
		if(vi==null){
			vh = new ViewHolder();
			vi = inf.inflate(R.layout.item_search_user, null);
			vh.ivUser = (ImageView)vi.findViewById(R.id.ivSearchUserList);
			vh.tvUserInfo = (TextView)vi.findViewById(R.id.tvSearchUserInfo);
			vi.setTag(vh);
		}else{
			vh = (ViewHolder) vi.getTag();
		}
		
		String url = ApplicationConstants.BASE_URL_IMAGE+mUserInfoList.get(position).getAvatarPath();
		Log.v("url: ", url +":"+ mUserInfoList.get(position).getUserName());
		ImageLoader.getInstance().displayImage(url, vh.ivUser, options);
		
		vh.tvUserInfo.setText(""+mUserInfoList.get(position).getUserName());
		return vi;
		
	}
	class ViewHolder{
		ImageView ivUser;
		TextView tvUserInfo;
	}


}
